package com.htfyun.ft.fragment.factory;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.htfyun.ft.R;

import java.util.Collections;
import java.util.List;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

public class RecyclerViewAdapterFTItems extends RecyclerView.Adapter<RecyclerViewAdapterFTItems.NormalViewHolder> {

    private List<FactoryTestItemsEnum> itemsEnumList = Collections.emptyList();

    private final LayoutInflater mInflater;

    public RecyclerViewAdapterFTItems(Context context) {
        mInflater = LayoutInflater.from(context);
    }
    @NonNull
    @Override
    public NormalViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View itemView = mInflater.inflate(R.layout.recycler_item_factory_main_test_items, parent, false);
        return new NormalViewHolder(itemView);
    }

    @Override
    public void onBindViewHolder(@NonNull NormalViewHolder holder, int position) {
        FactoryTestItemsEnum itemsEnum = itemsEnumList.get(position);
        String title = itemsEnum.getName();
        String summary = itemsEnum.getResult().getResultName();

        holder.title.setText(title);
        holder.summary.setText(summary);
        holder.itemView.setBackground(itemsEnum.getDrawable());

        holder.itemsEnum = itemsEnum;
    }

    @Override
    public int getItemCount() {
        return itemsEnumList.size();
    }

    public void setItemsEnumList(List<FactoryTestItemsEnum> itemsEnumList) {
        this.itemsEnumList = itemsEnumList;
        notifyDataSetChanged();
    }

    public static final class NormalViewHolder extends RecyclerView.ViewHolder {
        private final TextView title;
        private final TextView summary;

        private FactoryTestItemsEnum itemsEnum;

        private NormalViewHolder(View itemView) {
            super(itemView);
            title = (TextView) itemView.findViewById(R.id.title);
            summary = (TextView) itemView.findViewById(R.id.summary);
        }

        public FactoryTestItemsEnum getItemsEnum() {
            return itemsEnum;
        }
    }
}
